<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80"
            @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}"
            @reset="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="项目名称" name="projectName">
            <t-input
              v-model="queryParams.projectName"
              clearable
              placeholder="请输入项目名称"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="项目编号" name="projectNum">
            <t-input
              v-model="queryParams.projectNum"
              clearable
              placeholder="输入'空'查询未分配"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="申报年度" name="declareYear">
            <t-date-picker style="width: 240px" v-model="queryParams.declareYear" mode="year" clearable/>
          </t-form-item>
          <t-form-item label="承担单位" name="declareDeptName">
            <t-input
              v-model="queryParams.declareDeptName"
              clearable
              placeholder="请输入承担单位"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item v-if="site_tag === 'jtt'" label="计划类别" name="projectCategory">
            <t-tree-select filterable expand-all clearable v-model="queryParams.projectCategory" style="width: 240px"
                           :treeProps="{keys: {value: 'id',label:'name'}}"
                           :data="projectCategoryOptions"></t-tree-select>
          </t-form-item>
          <t-form-item label="学科分类" name="subjectClassification">
            <t-select style="width: 240px" clearable v-model="queryParams.subjectClassification"
                      :options="dict.type.subject_classification">
            </t-select>
          </t-form-item>
          <t-form-item label="项目类型" name="projectType">
            <t-select style="width: 240px" clearable v-model="queryParams.projectType"
                      :options="dict.type.project_type">
            </t-select>
          </t-form-item>
          <t-form-item label="项目状态" name="projectStatuss">
            <t-select :minCollapsedNum="1" style="width: 240px" multiple clearable v-model="queryParams.projectStatuss"
                      :options="ProjectStatusOptions">
            </t-select>
          </t-form-item>
          <t-form-item label="任务书状态" name="contractStatus">
            <t-select style="width: 240px" clearable v-model="queryParams.contractStatus"
                      :options="dict.type.contract_status">
            </t-select>
          </t-form-item>
          <t-form-item label="建议经费总概算">
            <t-form-item name="startAdviceFunding">
              <t-input
                v-model="queryParams.startAdviceFunding"
                clearable
                placeholder="大于等于"
                style="width: 120px"
              />
            </t-form-item>
            -
            <t-form-item name="endAdviceFunding">
              <t-input
                v-model="queryParams.endAdviceFunding"
                clearable
                placeholder="小于等于"
                style="width: 120px"
              />
            </t-form-item>
          </t-form-item>
          <t-form-item :label="site_tag==='jtt'?'厅拨经费':'集团补助经费'">
            <t-form-item name="startSubsidyFunding">
              <t-input
                v-model="queryParams.startSubsidyFunding"
                clearable
                placeholder="大于等于"
                style="width: 120px"
              />
            </t-form-item>
            -
            <t-form-item name="endSubsidyFunding">
              <t-input
                v-model="queryParams.endSubsidyFunding"
                clearable
                placeholder="小于等于"
                style="width: 120px"
              />
            </t-form-item>
          </t-form-item>
          <t-form-item label="项目负责人" name="projectLeaderName">
            <t-input
              v-model="queryParams.projectLeaderName"
              clearable
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="项目成员" name="projectMemberName">
            <t-input
              v-model="queryParams.projectMemberName"
              clearable
              style="width: 240px"
            />
          </t-form-item>

          <!--          <t-form-item label="申报日期" name="declareDateRange">-->
          <!--            <t-date-range-picker style="width: 280px" :placeholder="['开始时间','结束时间']" v-model="queryParams.declareDateRange"  allow-input clearable/>-->
          <!--          </t-form-item>-->
          <t-form-item label="任务书时间" name="projectDateRange">
            <t-date-range-picker style="width: 280px" v-model="queryParams.projectDateRange"
                                 :placeholder="['开始时间','结束时间']" allow-input clearable/>
          </t-form-item>
          <t-form-item label="管理单位" name="multilevelDeptId">
            <template slot="label">
              管理单位
              <t-tooltip content="查询当前单位及下级单位项目">
                <t-icon name="help-circle-filled"></t-icon>
              </t-tooltip>
            </template>
            <t-tree-select :treeProps="{keys: {value: 'id'}}" style="width:390px" clearable filterable
                           v-model="queryParams.multilevelDeptId" :data="deptMenuOptions"
                           placeholder="选择单位">
            </t-tree-select>
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <div class="btn-group-inline">
      <t-button @click="exportExcel" variant="outline" theme="primary">
        <t-icon name="download" slot="icon"/>
        导出
      </t-button>
    </div>
    <t-tabs v-if="site_tag === 'jtt'" @change="(val)=>{queryParams.projectCategory=val;getList();}"
            v-model="queryParams.projectCategory" style="margin-bottom: 10px">
      <t-tab-panel :key="item.id" :value="item.id" v-for="(item) in [{'name': '全部',id: null},...projectCategoryOptions]"
                   :label="item.name" :destroyOnHide="false">
      </t-tab-panel>
    </t-tabs>
    <t-table
      rowKey="id"
      size="small"
      :data="data"
      :columns="site_tag === 'jtt'?columns:columns.filter(val=>{ return  val.title!=='计划类别'})"
      hover
      :pagination="pagination"
      :loading="dataLoading"
      :selected-row-keys="selectedRowKeys"
      :sort="sort"
      :hideSortTips="true"
      @sort-change="sortChange"
    >
      <template #adviceFunding="{row}">
        {{ row.adviceFunding }}万元
      </template>
      <template #subsidyFunding="{row}">
        {{ row.subsidyFunding }}万元
      </template>
      <template #projectName="{ row }">
        <t-link v-if="row.version === '2024'" @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_item_detail=true;dialog.row=row" hover="color"
                theme="primary">{{ row.projectName }}
        </t-link>
        <t-link v-else @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_project_detail=true" hover="color"
                theme="primary">{{ row.projectName }}
        </t-link>
      </template>
      <template #op="{ row }">
        <t-button v-hasPermi="['*:*:*']" v-if="row.isOldProject!=='1'  && !['99'].includes(row.contractStatus)"
                  @click="addContract(row,1)" size="small"
                  variant="text" class="t-button-link">
          <t-icon name="edit-1" slot="icon"/>
          编辑
        </t-button>
        <t-button v-hasPermi="['*:*:*']" v-if="row.isOldProject==='1'  && !['99'].includes(row.contractStatus)"
                  @click="addContract(row,2)" size="small" variant="text"
                  class="t-button-link">
          <t-icon name="edit-1" slot="icon"/>
          编辑(历史数据录入)
        </t-button>
        <t-button v-if="![null].includes(row.contractStatus) && row.version ==='2024'"
                  @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_new_contract_detail=true;dialog.row=row"
                  size="small" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          任务书详情
        </t-button>
        <t-button v-else-if="![null].includes(row.contractStatus)"
                  @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_contract_detail=true"
                  size="small" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          任务书详情
        </t-button>
        <t-button v-if="![null].includes(row.contractStatus)" @click="createPDF(row)" size="small"
                  variant="text" class="t-button-link">
          <t-icon name="file-pdf" slot="icon"/>
          导出任务书PDF
        </t-button>
        <t-button
          @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_project_terminate=true"
          v-if="($store.state.user.roles.includes('kjcspy') || $store.state.user.roles.includes('admin')) && ['1','4',null].includes(row.contractStatus) && !['99'].includes(row.contractStatus)"
          theme="danger"
          size="small"
          variant="text" class="t-button-link">
          <t-icon name="stop-circle" slot="icon"/>
          项目终止
        </t-button>
      </template>
      <template #adviceFunding="{row}">
        {{row.adviceFunding}}万元
      </template>
      <template #subsidyFunding="{row}">
        {{row.subsidyFunding}}万元
      </template>
      <template #subjectClassification="{ row }">
        {{ row.subjectClassification | filterByDict(dict.type.subject_classification) }}
      </template>
      <template #projectType="{ row }">
        {{ row.projectType | filterByDict(dict.type.project_type) }}
      </template>
      <template #projectStatus="{ row }">
        <t-tag @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true"
               class="cursor-pointer" :theme="handleTheme(row.projectStatus, dict.type.project_status)" variant="light">
          {{ row.projectStatus | filterByDict(dict.type.project_status) }}
        </t-tag>
      </template>
      <template #contractStatus="{ row }">
        <t-tag @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true"
               class="cursor-pointer" v-if="row.contractStatus"
               :theme="handleTheme(row.contractStatus,dict.type.contract_status)" variant="light">
          {{ row.contractStatus | filterByDict(dict.type.contract_status) }}
        </t-tag>
        <t-tag @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true"
               class="cursor-pointer" v-else theme="warning" variant="light">未提交
        </t-tag>
      </template>
    </t-table>
    <project-detail-dialog tabDefaultValue="2" :header="dialog.header" :objId="dialog.objId"
                           :visible.sync="dialog.open_project_detail"
                           v-if="dialog.open_project_detail"></project-detail-dialog>
    <item-detail-dialog tabDefaultValue="2" :header="dialog.header" :objId="dialog.objId"
                           :visible.sync="dialog.open_item_detail"
                           v-if="dialog.open_item_detail" :row=dialog.row></item-detail-dialog>
    <contract-detail-dialog :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_contract_detail"
                            v-if="dialog.open_contract_detail"></contract-detail-dialog>
    <contract-new-detail-dialog :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_new_contract_detail" :row=dialog.row
                            v-if="dialog.open_new_contract_detail"></contract-new-detail-dialog>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list"
                  v-if="dialog.open_approve_list"></approve-list>
    <project-terminate @reload="getList" :header="dialog.header" :objId="dialog.objId"
                       :visible.sync="dialog.open_project_terminate"
                       v-if="dialog.open_project_terminate"></project-terminate>

  </div>
</template>

<script>

import ContractDetailDialog from "./components/contract-detail-dialog.vue";
import ApproveList from "../approve/components/approve-list.vue";
import ProjectDetailDialog from "../pm/components/project-detail-dialog.vue";
import ItemDetailDialog from "../pm/components/item-detail-dialog.vue";
import ProjectTerminate from "../components/project-terminate.vue";
import ContractNewDetailDialog from "./components/contract-new-detail-dialog.vue";


export default {
  name: "index",
  dicts: ["project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "duty", "platform_type", "member_type", "project_status", "contract_status"],
  components: {
    ContractDetailDialog,
    ApproveList,
    ProjectDetailDialog,
    ProjectTerminate,
    ItemDetailDialog,
    ContractNewDetailDialog
  },
  data() {
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      deptMenuOptions: [],
      sort: [],
      dialog: {
        open_project_detail: false,
        open_contract_detail: false,
        header: "",
        objId: 0,
        row: {},
        open_approve_list: false,
        open_project_terminate: false,
        open_item_detail: false,
        open_new_contract_detail: false,
      },
      projectCategoryOptions: [],
      queryParams: {
        declareYear: '',
        projectDateRange: [],
        declareDateRange: [],
        declareDate: '',
        rwsStartDate: '',
        rwsEndDate: '',
        startDeclareDate: '',
        endDeclareDate: '',
        startAdviceFunding: null,
        endAdviceFunding: null,
        startSubsidyFunding: '',
        endSubsidyFunding: '',
        projectLeaderName: '',
        projectMemberName: '',
        multilevelDeptId: null,
        pageNum: 1,
        pageSize: 10,
        projectCategory: null,
        projectName: '',
        projectType: '',
        projectNum: '',
        projectStatus: '',
        contractStatus: '',
        subjectClassification: '',
        dateRange: [],
        sortGroup: '',
        deptName: '',
        declareDeptName: '',
        projectStatuss: []
      },
      selectedRowKeys: [],
      selectedRowObj: {},
      data: [],
      columns: [
        // {
        //   colKey: "id",
        //   title: "项目编号",
        //   align: "center",
        //   ellipsis: true
        // },
        // {
        //   colKey: "declareDate",
        //   title: "申报年度",
        //   align: "center"
        // },
        {
          colKey: "projectNum",
          title: "项目编号",
          align: "center",
          width: 120,
          sorter: true,
          // ellipsis: true,
        },
        {
          colKey: "projectName",
          title: "项目名称",
          align: "center",
          // ellipsis: true,
          width: 220

        },

        {
          colKey: "adviceFunding",
          title: "建议经费总概算",
          align: "center",
          width: 160,
          sorter: true,
        },
        {
          colKey: "subsidyFunding",
          title: import.meta.env.VITE_SITE_TAG === 'jtt' ? "厅拨经费" : `集团补助经费`,
          align: "center",
          sorter: true,
          width: 140,
        },
        {
          colKey: "contractStartDate",
          title: "任务书开始时间",
          align: "center",
          sorter: true,
          width: 140,
        },
        {
          colKey: "contractCompleteDate",
          title: "任务书结束时间",
          align: "center",
          sorter: true,
          width: 140,
        },
        {
          colKey: "projectLeaderName",
          title: "项目负责人",
          align: "center",
          width: 100
        },
        {
          colKey: "nickName",
          title: "填报人",
          align: "center",
          width: 100
        },
        {
          colKey: "declareDeptName",
          title: "承担单位",
          align: "center",
          width: 180,
          sorter: true
        },
        {
          colKey: "projectCategoryName",
          title: "计划类别",
          align: "center",
          width: 120
        },
        {
          colKey: "subjectClassification",
          title: "学科分类",
          align: "center",
          width: 100
        },
        {
          colKey: "projectType",
          title: "项目类型",
          align: "center",
          width: 120
        },

        // {
        //   colKey: "attributeDeptName",
        //   title: "归口管理单位",
        //   align: "center"
        // },
        {
          colKey: "projectStatus",
          title: "项目状态",
          align: "center",
          width: 220,
          fixed: 'right',
          sorter: true
        },
        {
          colKey: "contractStatus",
          title: "任务书状态",
          align: "center",
          width: 120,
          fixed: 'right'
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 180,
          fixed: 'right'
        },
      ],
      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  computed: {
    ProjectStatusOptions() {
      let n
      if (this.dict.type.project_status) {
        n = [{label: '全选', checkAll: true}].concat(this.dict.type.project_status)
      }
      return n
    }
  },
  created() {
    Object.assign(this.queryParams, this.handelQuery(this.queryParams, this.$route.query))
    this.getList()
    this.getDeclareTree()
    this.getDeptTreeSelect();
  },
  methods: {
    createPDF(row) {
      const instance = this.$loading({
        fullscreen: true,
        attach: 'body',
        preventScrollThrough: false,
      });
      this.$api.kjxm.contract.createPDF(row.id, 1).then(response => {
        window.open(response.data.fullFilePath, '_blank')
        instance.hide();
      }).catch((e) => {
        instance.hide();
        this.$message.error(e.toString());
      });
    },
    exportExcel() {
      this.$download(`/kjxm/excel/allContractList`, this.queryParams, `任务书列表_${new Date().getTime()}.xls`)
    },
    getDeptTreeSelect() {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
        // this.menuOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeclareTree() {
      this.$api.kjxm.project.planCategoryList().then(response => {
        this.projectCategoryOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    sortChange(sort) {
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if (sort instanceof Array) {
        orderByColumn = sort.map(val => val.sortBy)
        isAsc = sort.map(val => val.descending ? `desc` : `asc`)
      } else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending ? `desc` : `asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    addContract(row, type) {
      if(this.site_tag === 'jtt' && row?.version === '2024'){
        if(row.contractId){
          this.$api.kjxm.contract.getNewAll(row.id).then(response => {
            const taskId = row.id;
            const activeFormList = [];
            sessionStorage.removeItem(`${taskId}-kjxm-contract-activeForm`);
            sessionStorage.setItem(`${taskId}-kjxm-contract-step1`, row.contractId);
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step2`);
            if (response.data.contractOverview && response.data.contractOverview.id) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step2`, response.data.contractOverview.id)
            } else {
              activeFormList.push(2);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step3`);
            if (response.data.projectBudget && response.data.projectBudget.id) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step3`, response.data.projectBudget.id)
            } else {
              activeFormList.push(3);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step4`);
            if (response.data.researchPlanList && response.data.researchPlanList.length > 0) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step4`, response.data.researchPlanList.length)
            } else {
              activeFormList.push(4);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step5`);
            if (response.data.expectResultsList && response.data.expectResultsList.length > 0) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step5`, response.data.expectResultsList.length)
            } else {
              activeFormList.push(5);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step6`);
            if (response.data.contractResults && response.data.contractResults.id) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step6`, response.data.contractResults.id)
            } else {
              activeFormList.push(6);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step7`);
            if (response.data.projectCompanyList && response.data.projectCompanyList.length > 0) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step7`, response.data.projectCompanyList.length)
            } else {
              activeFormList.push(7);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step8`);
            if (response.data.projectMemberList && response.data.projectMemberList.length > 0) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step8`, response.data.projectMemberList.length)
            } else {
              activeFormList.push(8);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step9`);
            if (response.data?.contractTerms && response.data?.contractTerms.length > 0) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step9`, response.data?.contractTerms.length)
            } else {
              activeFormList.push(9);
            }
            sessionStorage.removeItem(`${taskId}-kjxm-contract-step10`);
            if (response.data?.contractExplain && response.data?.contractExplain?.id) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-step10`, response.data.contractExplain.id)
            } else {
              activeFormList.push(10);
            }

            if (activeFormList.length <= 0) {
              sessionStorage.setItem(`${taskId}-kjxm-contract-activeForm`, 10); // 跳转到最后一步
            } else {
              sessionStorage.setItem(`${taskId}-kjxm-contract-activeForm`, activeFormList[0]); // 跳转到第一个不满足
            }
            this.$router.push({
              path: `/kjxm/other/contract/contract-apply/${taskId}`,
              query: {title: `${response.data.projectName}-任务书签订`}
            });

          }).catch((e) => {
            this.$message.error(e.toString());
          });
        }else {
          this.$router.push(`/kjxm/other/contract/contract-apply/${row.id}`);
        }
      }else {
        sessionStorage.removeItem(`${row.id}-contract-activeForm`)
        if (row.contractId) {
          sessionStorage.setItem(`${row.id}-contractId`, row.contractId)
          this.$api.kjxm.contract.getAll(row.id).then(response => {
            const taskId = row.id;
            const activeFormList = [];
            sessionStorage.removeItem(`${taskId}-contract-contractId`);
            sessionStorage.setItem(`${taskId}-contract-contractId`, row.contractId)

            sessionStorage.removeItem(`${taskId}-contract-purposeContentId`);
            if (response.data?.contractPurposeContent && response.data?.contractPurposeContent?.id) {
              sessionStorage.setItem(`${taskId}-contract-purposeContentId`, response.data.contractPurposeContent.id)
            } else {
              activeFormList.push(1);
            }
            sessionStorage.removeItem(`${taskId}-contract-assessIndexId`);
            if (response.data?.contractAssessIndex && response.data?.contractAssessIndex?.id) {
              sessionStorage.setItem(`${taskId}-contract-assessIndexId`, response.data.contractAssessIndex.id)
            } else {
              activeFormList.push(2);
            }
            sessionStorage.removeItem(`${taskId}-contract-researchPlanId`);
            if (response.data?.contractResearchPlans && response.data?.contractResearchPlans.length > 0) {
              sessionStorage.setItem(`${taskId}-contract-researchPlanId`, response.data?.contractResearchPlans.length)
            } else {
              activeFormList.push(3);
            }
            sessionStorage.removeItem(`${taskId}-contract-resultsId`);
            if (response.data?.contractResults && response.data?.contractResults?.id) {
              sessionStorage.setItem(`${taskId}-contract-resultsId`, response.data.contractResults.id)
            } else {
              activeFormList.push(4);
            }
            sessionStorage.removeItem(`${taskId}-contract-companyId`);
            if (response.data?.projectCompanyList && response.data?.projectCompanyList.length > 0) {
              sessionStorage.setItem(`${taskId}-contract-companyId`, response.data?.projectCompanyList.length)
            } else {
              activeFormList.push(5);
            }
            sessionStorage.removeItem(`${taskId}-contract-memberId`);
            if (response.data?.projectMemberList && response.data?.projectMemberList.length > 0) {
              sessionStorage.setItem(`${taskId}-contract-memberId`, response.data?.projectMemberList.length)
            } else {
              activeFormList.push(6);
            }
            sessionStorage.removeItem(`${taskId}-contract-budgetId`);
            if (response.data?.projectBudget && response.data?.projectBudget?.id) {
              sessionStorage.setItem(`${taskId}-contract-budgetId`, response.data.projectBudget.id)
            } else {
              activeFormList.push(7);
            }
            sessionStorage.removeItem(`${taskId}-contract-termsId`);
            if (response.data?.contractTerms && response.data?.contractTerms.length > 0) {
              sessionStorage.setItem(`${taskId}-contract-termsId`, response.data?.contractTerms.length)
            } else {
              activeFormList.push(8);
            }
            sessionStorage.removeItem(`${taskId}-contract-reviewId`);
            if (response.data?.contractExplain && response.data?.contractExplain?.id) {
              sessionStorage.setItem(`${taskId}-contract-reviewId`, response.data.contractExplain.id)
            } else {
              activeFormList.push(9);
            }
            sessionStorage.removeItem(`${taskId}-contract-otherId`);
            if (response.data?.contractOthers && response.data?.contractOthers?.id) {
              sessionStorage.setItem(`${taskId}-contract-otherId`, response.data.contractOthers.id)
            } else {
              activeFormList.push(10);
            }
            if (activeFormList.length <= 0) {
              sessionStorage.setItem(`${taskId}-contract-activeForm`, type === 1 ? 10 : 11); // 跳转到最后一步
            } else {
              sessionStorage.setItem(`${taskId}-contract-activeForm`, activeFormList[0]); // 跳转到第一个不满足
            }
            if (type === 1) {
              this.$router.push(`/kjxm/other/contract/project-contract/${row.id}`);
            } else {
              this.$router.push({
                path: `/kjxm/other/contract/project-contract/${row.id}`,
                query: {
                  isOldProject: '1',
                  title: '任务书签订(历史数据录入)',
                }
              })
            }
          }).catch((e) => {
            this.$message.error(e.toString());
          });
        } else {
          if (type === 1) { // eslint-disable-line
            this.$router.push(`/kjxm/other/contract/project-contract/${row.id}`);
          } else {
            this.$router.push({
              path: `/kjxm/other/contract/project-contract/${row.id}`,
              query: {
                isOldProject: '1',
                title: '任务书签订(历史数据录入)',
              }
            })
          }
        }
      }
    },
    getList() {
      this.dataLoading = true;
      [this.queryParams.rwsStartDate, this.queryParams.rwsEndDate] = this.queryParams.projectDateRange;
      [this.queryParams.startDeclareDate, this.queryParams.endDeclareDate] = this.queryParams.declareDateRange;
      this.$api.kjxm.contract.list(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
  },
}
</script>

<style scoped>

</style>
